﻿namespace ImageWallControl
{
    using System;
    using System.Windows;
    using System.Windows.Controls;

    public class PhotoWall : Panel
    {
        protected override Size MeasureOverride(Size availableSize)
        {
            var cols = (int)Math.Ceiling(availableSize.Width / ImageWall.SectionWidth);
            for (int i = 0; i < cols; i++)
            {
                Children.Add(new ImageWall());
            }
            return availableSize;
        }
        protected override Size ArrangeOverride(Size finalSize)
        {
            var currentX = 0f;
            var size = new Size(ImageWall.SectionWidth, ImageWall.SectionHeight);
            foreach (var child in Children)
            {
                var location = new Point(currentX, 0);
                child.Arrange(new Rect(location, size));
                currentX += ImageWall.SectionWidth;
            }
            return base.ArrangeOverride(finalSize);
        }
    }
}